namespace MsForgeReboot.Services.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class UserGroupIsFirstClassObject : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.UserGroups",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Body = c.String(nullable: false),
                        Published = c.DateTime(nullable: false),
                        Title = c.String(nullable: false, maxLength: 200),
                        UrlPointer = c.String(nullable: false, maxLength: 200),
                        Author_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Users", t => t.Author_Id)
                .Index(t => t.Author_Id);
            
            AddColumn("dbo.Users", "UserGroup_Id", c => c.Int());
            AddColumn("dbo.Events", "OrganizedBy_Id", c => c.Int());
            AddForeignKey("dbo.Users", "UserGroup_Id", "dbo.UserGroups", "Id");
            AddForeignKey("dbo.Events", "OrganizedBy_Id", "dbo.UserGroups", "Id");
            CreateIndex("dbo.Users", "UserGroup_Id");
            CreateIndex("dbo.Events", "OrganizedBy_Id");
            DropColumn("dbo.Events", "UserGroup");
        }
        
        public override void Down()
        {
            AddColumn("dbo.Events", "UserGroup", c => c.String(nullable: false, maxLength: 100));
            DropIndex("dbo.UserGroups", new[] { "Author_Id" });
            DropIndex("dbo.Events", new[] { "OrganizedBy_Id" });
            DropIndex("dbo.Users", new[] { "UserGroup_Id" });
            DropForeignKey("dbo.UserGroups", "Author_Id", "dbo.Users");
            DropForeignKey("dbo.Events", "OrganizedBy_Id", "dbo.UserGroups");
            DropForeignKey("dbo.Users", "UserGroup_Id", "dbo.UserGroups");
            DropColumn("dbo.Events", "OrganizedBy_Id");
            DropColumn("dbo.Users", "UserGroup_Id");
            DropTable("dbo.UserGroups");
        }
    }
}
